package com.jz;

import com.jz.socket.HeartBeatClientThread;
import com.jz.util.AttributeSupport;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Administrator on 2015/10/21.
 */
abstract public class JZClient {
    public static final Logger log = LoggerFactory.getLogger(JZClient.class);
    private HeartBeatClientThread thread;
    private boolean isDebug = true;
    public JZClient(boolean isDebug) {
        this.isDebug = isDebug;
        init();
        clientInit();
    }

    private void init() {
        PropertyConfigurator.configure(System.getProperty("user.dir")
                + "/conf/log4j.properties");
        try{
            log.info("init heartbeat client");
            if(!isDebug){
                thread = new HeartBeatClientThread(AttributeSupport.HEARTBEAT_IP, AttributeSupport.HEARTBEAT_PORT);
                thread.start();
            }
        }catch (Exception e){
            log.error(e.getMessage());
        }
    }

    /**
     * 本地初始化
     * */
    abstract public void clientInit();

    public static void main(String[] args){
        new JZClient(false) {
            @Override
            public void clientInit() {

            }
        };
    }
}
